home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-08 | 55.3 KB | 1,675 lines |
- ; $Id: d_object3d.pro,v 1.29 1997/04/25 22:40:20 alan Exp $
- ;
- ; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
- ; Unauthorized reproduction prohibited.
- ;
- ;+
- ; FILE:
- ; d_object3d.pro
- ;
- ; CALLING SEQUENCE: d_object3d
- ;
- ; PURPOSE:
- ; Shows geometric objects (molecules and others.)
- ;
- ; MAJOR TOPICS: Visualizaton and widgets
- ;
- ; CATEGORY:
- ; IDL 5.0
- ;
- ; INTERNAL FUNCTIONS and PROCEDURES:
- ; fun makespheres - Create a shere
- ; fun makemolecule - Create a molecule
- ; fun moleread - Read the molecule file
- ; pro new_select - Handle a new selection
- ; pro panimate - Animate (with pattern keyword)
- ; pro o3d_animate - Animate (with pattern keyword)
- ; pro toggle_state - Toggle off and on
- ; fun read_noff - Read the object file
- ; pro d_object3d_Event - Event handler
- ; pro d_object3d_Cleanup - Cleanup
- ; pro d_object3d - Main procedure
- ;
- ; EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
- ; pro gettips - Get tip text structure.
- ; pro widtips - Create widget text for tips.
- ; pro puttips - Change the text display (tip)
- ; object3d.txt
- ; object3d.tip
- ; knot.nof
- ; seashell.nof
- ; teapot.nof
- ; aspartam.mol
- ; caffeine.mol
- ; valium.mol
- ; pro orb__define.pro - Create an orb object
- ; pro trackball__define.pro - Create a trackball object
- ;
- ; REFERENCE: IDL Reference Guide, IDL User's Guide
- ;
- ; NAMED STRUCTURES:
- ; none.
- ;
- ; COMMON BLOCS:
- ; none.
- ;
- ; MODIFICATION HISTORY:
- ; 9/96, DD - Written.
- ; 10/96, DAT - New GUI and combining molecule and objects.
- ;-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: Create a sphere for each atom type.
- ;
- function makespheres
-
- o = objarr(8)
-
- o(0) = OBJ_NEW('orb', COLOR=[128,128,128], RADIUS=1.5) ; C
- o(1) = OBJ_NEW('orb', COLOR=[255,255,255], RADIUS=0.9) ; H
- o(2) = OBJ_NEW('orb', COLOR=[0,0,255], RADIUS=1.5) ; N
- o(3) = OBJ_NEW('orb', COLOR=[230,230,0], RADIUS=1.5) ; S
- o(4) = OBJ_NEW('orb', COLOR=[25,25,0], RADIUS=1.5) ; X
- o(5) = OBJ_NEW('orb', COLOR=[240,0,153], RADIUS=4.7) ; Ce
- o(6) = OBJ_NEW('orb', COLOR=[204,25,230], RADIUS=1.3) ; BR
- o(7) = OBJ_NEW('orb', COLOR=[255,0,0], RADIUS=1.46) ; O
-
- RETURN, o
- end
-
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: Create the molecule. Return it in a model.
- ;
- function makemolecule, $
- n_atoms, $ ; IN: number of atoms in the molecule
- atom_xyz, $ ; IN: position of each atoms
- atoms, $ ; IN: atom type
- objs ; IN: atom object
-
- m = OBJ_NEW('IDLgrModel')
-
- for i=0,n_atoms-1 do begin
- s = objs(atoms(i))
- s->GetProperty, POBJ=sh
- sh->GetProperty, COLOR=col, POLY=pmesh
- p = OBJ_NEW('IDLgrPolygon', SHARE_DATA=sh, POLY=pmesh, COLOR=col)
- p->SetProperty, SHADING=1, UVALUE=-1
-
- mm = OBJ_NEW('IDLgrModel', /SELECT_TARGET)
- mm->SetProperty, UVALUE=atoms(i)
- mm->Translate, atom_xyz(0,i), atom_xyz(1,i), atom_xyz(2,i)
- mm->Add, p
-
- m->Add, mm
- endfor
-
- RETURN, m
- end
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: Read the molecule data input file.
- ;
- function molread, $
- file, $ ; IN: filename
- atom_xyz_r, $
- atoms_r
-
- n_atoms = 0
- atom_xyz = FLTARR(3,1000)
- atoms = INTARR(1000)
-
- GET_LUN, lun
-
- OPENR, lun, filepath(file, $
- SUBDIR=['examples','demo','demodata'])
-
- s = " "
-
- while (n_atoms LT 1000) do begin
-
- on_ioerror, endoffile
- READF, lun, s
-
- i = STRPOS(s,":")
-
- if (i NE -1) then begin
- READS, strmid(s,i+1,strlen(s)-i+1),x,y,z
- a_type = -1
-
- case strmid(s,0,2) of
- "C:" : a_type = 0
- "H:" : a_type = 1
- "N:" : a_type = 2
- "S:" : a_type = 3
- "X:" : a_type = 4
- "Ce" : a_type = 5
- "BR" : a_type = 6
- "O:" : a_type = 7
- else : a_type = -1
- endcase
-
- if (a_type NE -1) then begin
- atom_xyz(0,n_atoms) = x
- atom_xyz(1,n_atoms) = y
- atom_xyz(2,n_atoms) = z
- atoms(n_atoms) = a_type
- n_atoms = n_atoms + 1
- endif
- endif
- endwhile
-
- endoffile:
-
- CLOSE, lun
-
- FREE_LUN,lun
-
- if (n_atoms GE 0) then begin
- atoms_r = atoms(0:n_atoms-1)
- atom_xyz_r = atom_xyz(*,0:n_atoms-1)
- end
-
- RETURN, n_atoms
-
- end ; of molread
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: Reinitialize the selection state (picking).
- ;
- pro new_select, $
- state, $
- obj=target
-
- if (state.is_sel NE 0) then begin
- state.cur_sel->SetProperty,STYLE=2
- state.is_sel = 0
- endif
-
- if (N_ELEMENTS(target) NE 0) then begin
- state.is_sel = 1
- state.cur_sel = target
- state.cur_sel->SetProperty, STYLE=1
- endif
- end ; of new_select
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: Animate
- ;
- pro panimate, $
- state, $ ; IN: state structure
- what ; IN: what to animate
-
- state.oSurface(state.cur_obj)->GetProperty, FILL_PATTERN=pobj
-
- spacing=5.0
- for i=0,180,10 do begin
- pobj->SetProperty, ORIENTATION=i, SPACING=spacing
- state.oWindow->Draw, state.oView
- spacing = spacing + 1.0
- if (spacing GE 20.0) then spacing = 5.0
- endfor
- end
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: Animate
- ;
- pro o3d_animate, $
- state, $ ; IN: state structure
- what ; IN: what to animate
-
- ; get the verts
- ;
- state.oSurface(state.cur_obj)->GetProperty, DATA=verts
- v1 = verts
-
- for i=10,2,-2 do begin
- v1(2,*) = verts(2,*)*(float(i)/10.0)
- state.oSurface(state.cur_obj)->SetProperty,DATA=v1
- state.oWindow->Draw, state.oView
- endfor
- for i=-2,-10,-2 do begin
- v1(2,*) = verts(2,*)*(float(i)/10.0)
- state.oSurface(state.cur_obj)->SetProperty,DATA=v1
- state.oWindow->Draw, state.oView
- endfor
- for i=-10,-2,2 do begin
- v1(2,*) = verts(2,*)*(float(i)/10.0)
- state.oSurface(state.cur_obj)->SetProperty,DATA=v1
- state.oWindow->Draw, state.oView
- endfor
- for i=2,10,2 do begin
- v1(2,*) = verts(2,*)*(float(i)/10.0)
- state.oSurface(state.cur_obj)->SetProperty,DATA=v1
- state.oWindow->Draw, state.oView
- endfor
-
- ; prevent decay...
- ;
- state.oSurface(state.cur_obj)->SetProperty,DATA=verts
-
- end ; of o3d_animate
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: toggle off and on state.
- ;
- function Toggle_state, $
- wid ; IN: widget identifier
-
- WIDGET_CONTROL, wid, GET_VALUE=name
-
- s = STRPOS(name,'(off)')
- if (s NE -1) then begin
- STRPUT,name,'(on )',s
- ret = 1
- endif else begin
- s = STRPOS(name,'(on )')
- STRPUT,name,'(off)',s
- ret = 0
- endelse
-
- WIDGET_CONTROL, wid, SET_VALUE=name
-
- RETURN, ret
- end ; of Toggle_state,
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: This reads a modified .off format
- ; file (header removed, one ptype...)
- ;
- function read_noff, $
- file, $ ; IN: filename
- parent, $ ; IN: parent model for the created polyline object
- xr, $ ; OUT: x radius
- yr, $ ; OUT: y radius
- zr ; OUT: z radius
-
- s = ' '
- npsize = 1
-
- GET_LUN, lun
-
- OPENR, lun, filepath(file, $
- SUBDIR=['examples','demo','demodata'])
-
- nverts=0L
- npatches=0L
- nconn=0L
- psize=0L
- READF, lun, nverts, npatches, nconn, psize
-
- x = FLTARR(nverts, /NOZERO)
- y = FLTARR(nverts, /NOZERO)
- z = FLTARR(nverts, /NOZERO)
-
- for i=0, nverts-1 do begin
- READF,lun,xp,yp,zp
- x(i)=xp
- y(i)=yp
- z(i)=zp
- endfor
-
- if (psize NE -1) then begin
- msize=npatches*(psize+1)
- endif else begin
- msize = nconn + npatches
- endelse
-
- mesh = LONARR(msize)
-
- j = 0
- m1=0L
- m2=0L
- m3=0L
- m4=0L
- for i=0,npatches-1 do begin
- if (psize NE -1) then begin
- mesh(j) = psize
- if (psize EQ 3) then begin
- READF, lun, dummy, m1, m2, m3
- mesh(j+1)=m1
- mesh(j+2)=m2
- mesh(j+3)=m3
- endif else begin
- READF, lun, dummy, m1, m2, m3, m4
- mesh(j+1)=m1
- mesh(j+2)=m2
- mesh(j+3)=m3
- mesh(j+4)=m4
- endelse
- j = j + psize+1
- endif else begin
- READF, lun, s
- READS, s, npsize
- arr = LONARR(npsize+1)
- READS, s, arr
- mesh(j:j+npsize) = arr
- j = j + npsize+1
- endelse
- endfor
- ;CLOSE, lun
-
- FREE_LUN, lun
-
- ;xr = FLTARR(2)
- ;xr(0) = MIN(x)
- ;xr(1) = MAX(x)
- xmin=MIN(x, max=xmax)
- xr=[xmin, xmax]
-
- ;yr = FLTARR(2)
- ;yr(0) = MIN(y)
- ;yr(1) = MAX(y)
- ymin=MIN(y, max=ymax)
- yr=[ymin, ymax]
-
- ;zr = FLTARR(2)
- ;zr(0) = MIN(z)
- ;zr(1) = MAX(z)
- zmin=MIN(z, max=zmax)
- zr=[zmin, zmax]
-
- ; remap to +-1
- ;
- ;sc = FLTARR(3)
- ;sc(0) = xr(1) - xr(0)
- ;sc(1) = yr(1) - yr(0)
- ;sc(2) = zr(1) - zr(0)
- sc = MAX([xmax - xmin, ymax - ymin, zmax - zmin])
-
- ;xr(0) = (xr(1) + xr(0))/2.0
- ;yr(0) = (yr(1) + yr(0))/2.0
- ;zr(0) = (zr(1) + zr(0))/2.0
- xav = (xmax + xmin)/2.0
- yav = (ymax + ymin)/2.0
- zav = (zmax + zmin)/2.0
-
- ;if ((sc(2) GT sc(1)) AND (sc(2) GT sc(0))) then begin
- ; sc(0) = sc(2)
- ;endif else if ((sc(1) GT sc(0)) AND (sc(1) GT sc(2))) then begin
- ; sc(0) = sc(1)
- ;endif
- ;;;sc[0] = MAX(sc)
-
-
- ;for i=0,nverts-1 do begin
- ; x(i) = (x(i)-xr(0))/sc(0)
- ; y(i) = (y(i)-yr(0))/sc(0)
- ; z(i) = (z(i)-zr(0))/sc(0)
- ;endfor
- ;;x = (x-xr(0))/sc(0)
- ;;y = (y-yr(0))/sc(0)
- ;;z = (z-zr(0))/sc(0)
- x = (x-xav)/sc
- y = (y-yav)/sc
- z = (z-zav)/sc
-
- xr = [-0.7, 0.7]
- yr = [-0.7, 0.7]
- zr = [-0.7, 0.7]
-
- s = OBJ_NEW("IDLgrPolygon", TRANSPOSE([[x],[y],[z]]), $
- SHADING=1, $
- POLY=mesh, COLOR=[200,200,200])
-
- parent->Add, s
-
- RETURN,s
-
- end ; of read_noff
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: This reads a flat binary file containing the mesh
-
- ;
- function object3d_read_data, $
- file, $ ; IN: filename
- parent, $ ; IN: parent model for the created polyline object
- xr, $ ; OUT: x radius
- yr, $ ; OUT: y radius
- zr ; OUT: z radius
-
- s = ' '
-
- RESTORE, filepath(file, $
- SUBDIR=['examples','demo','demodata'])
-
- xmin=MIN(x, max=xmax)
- xr=[xmin, xmax]
-
- ymin=MIN(y, max=ymax)
- yr=[ymin, ymax]
-
- zmin=MIN(z, max=zmax)
- zr=[zmin, zmax]
-
- sc = MAX([xmax - xmin, ymax - ymin, zmax - zmin])
-
- xav = (xmax + xmin)/2.0
- yav = (ymax + ymin)/2.0
- zav = (zmax + zmin)/2.0
-
- x = (x-xav)/sc
- y = (y-yav)/sc
- z = (z-zav)/sc
-
- xr = [-0.7, 0.7]
- yr = [-0.7, 0.7]
- zr = [-0.7, 0.7]
-
- s = OBJ_NEW("IDLgrPolygon", TRANSPOSE([[x],[y],[z]]), $
- SHADING=1, $
- POLY=mesh, COLOR=[200,200,200])
-
- parent->Add, s
-
- RETURN,s
-
- end ; of object3d_read_data
-
- ;----------------------------------------------------------------------
- ;
- ; Purpose: Event handler of the geometric shapes.
- ;
- pro d_object3d_event, $
- sEvent ; IN: event structure
-
- ; Quit the application using the close box.
- ;
- if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
- 'WIDGET_KILL_REQUEST') then begin
- WIDGET_CONTROL, sEvent.top, /DESTROY
- RETURN
- endif
-
- WIDGET_CONTROL, sEvent.id, GET_UVALUE=uval
-
- case uval of
-
- ; Set scaling.
- ;
- 'SCALING': begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, $
- state.widgetIDStr.wScalingSlider, GET_VALUE=scale
- scale = 0.75 + FLOAT(scale) / 100.0
- scalep = scale*100.0
- scalingString = 'Scaling : ' + STRING(scalep, $
- FORMAT='(f5.1)') + ' %'
- WIDGET_CONTROL, state.widgetIDStr.wScalingLabel, $
- SET_VALUE=scalingString
-
- transform = [[scale*0.7, 0, 0, 0.0], [0, scale*0.7, 0, 0.0], $
- [0, 0, scale*0.7, 0.0], [0, 0, 0, 1]]
- transformmol = [[scale*.3, 0, 0, 0.0], [0, scale*.3, 0, 0.0], $
- [0, 0, scale*.3, 0.0], [0, 0, 0, 1]]
- state.oMoleModel->SetProperty, TRANSFORM = transformmol
- state.oShapeModel->SetProperty, TRANSFORM = transform
-
- WIDGET_CONTROL, state.widgetIDStr.wBase, /HOURGLASS
- state.oWindow->draw,State.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of SCALING
-
- ; Set line thickness to 1 point.
- ;
- 'THCK1': begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, state.widgetIDStr.wThk1, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wThk3, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk5, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk7, SENSITIVE=1
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,thick=1.0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of THCK1
-
- ; Set line thickness to 3 points.
- ;
- 'THCK3': begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, state.widgetIDStr.wThk1, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk3, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wThk5, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk7, SENSITIVE=1
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,thick=3.0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of THCK3
-
- ; Set line thickness to 5 points.
- ;
- 'THCK5': begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, state.widgetIDStr.wThk1, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk3, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk5, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wThk7, SENSITIVE=1
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,thick=5.0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of THCK5
-
- ; Set line thickness to 7 points.
- ;
- 'THCK7': begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, state.widgetIDStr.wThk1, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk3, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk5, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThk7, SENSITIVE=0
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,thick=7.0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of THCK7
-
- ; Animate the object.
- ;
- 'PANIMATE': begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=0
- panimate, state, 0
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of PANIMATE
-
- ; Select and show a new geometric object.
- ;
- 'OBJ': begin
- WIDGET_CONTROL, /HOURGLASS
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=0
- WIDGET_CONTROL, sEvent.id, GET_VALUE=bgroupIndex
- if bgroupIndex LT state.max_obj then begin
- ; Handle the shell, knot, teapot
- ;
- WIDGET_CONTROL, state.widgetIDStr.wEditButton, SENSITIVE=1
- state.oMoleModel->SetProperty, HIDE=1
- state.oView->SetProperty, COLOR=[0, 0, 0]
- state.oShapeModel->SetProperty, HIDE=0
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, HIDE=1
- state.sh(i)->SetProperty, HIDE=1
- endfor
- state.cur_obj = bgroupIndex
- state.oSurface(state.cur_obj)->SetProperty, HIDE=0
- if (state.edging EQ 1) then begin
- state.sh(state.cur_obj)->SetProperty, HIDE=0
- endif
-
- state.oWindow->Draw, state.oView
- textChange = ['inter','mouse']
- putTips, state.sText, state.wText[1], $
- textChange, [1,2]
- state.modelFlag = 1
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- endif else begin
- ; Handle the molecules
- ;
- WIDGET_CONTROL, state.widgetIDStr.wEditButton, SENSITIVE=0
- new_select, state
- state.oMoleModel->SetProperty, HIDE=0
- state.oView->SetProperty, COLOR=[30, 90, 30]
- state.oShapeModel->SetProperty, HIDE=1
- for i=0,state.nMolecule*2-1 do begin
- state.oMolecule(i)->SetProperty, HIDE=1
- endfor
-
- ; bgroupIndex is the item number from the bgroup
- ; the molecules are after the other objects in the bgroup
- ;
- state.cur_mol = bgroupIndex - state.max_obj
- state.oMolecule(state.cur_mol)->SetProperty, HIDE=0
- state.oWindow->Draw, state.oView
- textChange = ['molec','right']
- putTips, state.sText, state.wText[1], $
- textChange, [1,2]
-
- state.modelFlag = 0
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- endelse
- end ; of OBJ
-
- ; Add or remove the vertices colors.
- ;
- 'VERTC' : begin
-
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- j = Toggle_State(sEvent.id)
- case j of
-
- ; Remove the colors.
- ;
- 0: begin
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, VERT_COLORS=0
- endfor
- end ; of 0
-
- ; Add the colors.
- ;
- 1: begin
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, $
- VERT_COLORS=state.vc
- endfor
- end ; of 0
-
- endcase
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of VERTC
-
- ; Show the vertices as points.
- ;
- 'POINTS' : BEGIN
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- for i=0,state.max_obj-1 do state.oSurface(i)->SetProperty,STYLE=0
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,hidden_line=0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wPointsButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wWireButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wSolidButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wPointHButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWirehButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThickButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wBottomButton, SENSITIVE=0
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of POINTS
-
- ; Set the object style to wire.
- ;
- 'WIRE' : BEGIN
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,STYLE=1
- endfor
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,hidden_line=0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wPointsButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWireButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wSolidButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wPointHButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWirehButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThickButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wBottomButton, SENSITIVE=0
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of WIRE
-
- ; Set the object style to solid surface.
- ;
- 'SOLID' : BEGIN
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,STYLE=2
- endfor
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,hidden_line=0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wPointsButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWireButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wSolidButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wPointHButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWirehButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThickButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wBottomButton, SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of SOLID
-
- ; Set the object style to hidden points.
- ;
- 'POINTSH' : BEGIN
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, STYLE=0
- endfor
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, /HIDDEN_LINE
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wPointsButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWireButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wSolidButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wPointHButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wWirehButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wThickButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wBottomButton, SENSITIVE=0
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of POINTSH
-
- ; Set the object style to hidden wire.
- ;
- 'WIREH' : BEGIN
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,STYLE=1
- endfor
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty,/hidden_line
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wPointsButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWireButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wSolidButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wPointHButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wWirehButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wThickButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wBottomButton, SENSITIVE=0
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of WIREH
-
- ; Add or remove the color of the polygon bottom side.
- ;
- 'BOTTOM' : begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- j = Toggle_State(sEvent.id)
-
- if (j EQ 0) then begin
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, BOTTOM=[64,192,128]
- endfor
- endif else begin
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, BOTTOM=0
- endfor
- endelse
-
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of BOTTOM
-
- ; Add or remove the back face culiing option. Back face culling
- ; on will hide the polygon when seen from its bottom side.
- ;
- 'BACKF' : begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- j = Toggle_State(sEvent.id)
- for i=0, state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, REJECT=j
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of BACKF
-
- ; Add or remove edges.
- ;
- 'EDGING' : begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- state.edging = Toggle_State(sEvent.id)
-
- if (state.edging EQ 1) then begin
- state.sh(state.cur_obj)->SetProperty, HIDE=0
- endif else begin
- state.sh(state.cur_obj)->SetProperty, HIDE=1
- endelse
-
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of EDGING
-
- ; Set the drag quality to low.
- ;
- 'LOW' : begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- state.dragq = 0
- WIDGET_CONTROL, state.widgetIDStr.wLowButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wMediumButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wHighButton, SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of LOW
-
- ; Set the drag quality to medium.
- ;
- 'MEDIUM' : begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- state.dragq = 1
- WIDGET_CONTROL, state.widgetIDStr.wLowButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wMediumButton, SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wHighButton, SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of MEDIUM
-
- ; Set the drag quality to high.
- ;
- 'HIGH' : begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- state.dragq = 2
- WIDGET_CONTROL, state.widgetIDStr.wLowButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wMediumButton, SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wHighButton, SENSITIVE=0
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of HIGH
-
- ; Set the object shading to flat.
- ;
- 'FLAT' : BEGIN
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, SHADING=0
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wFlatButton, $
- SENSITIVE=0
- WIDGET_CONTROL, state.widgetIDStr.wGouraudButton, $
- SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of FLAT
-
- ; Set the object shading to Gouraud.
- ;
- 'GOURAUD' : BEGIN
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- for i=0,state.max_obj-1 do begin
- state.oSurface(i)->SetProperty, SHADING=1
- endfor
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wFlatButton, $
- SENSITIVE=1
- WIDGET_CONTROL, state.widgetIDStr.wGouraudButton, $
- SENSITIVE=0
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of GOURAUD
-
- ; Reorient the object to its initial state.
- ;
- 'RESETTRANSFORM' : begin
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=0
- state.oShape0Model->SetProperty, TRANSFORM=state.tmg0
- state.oShape1Model->SetProperty, TRANSFORM=state.tmg1
- state.oSub1MoleModel->SetProperty, TRANSFORM=state.tmmolecule
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=1
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
- end ; of RESETTRANSFORM
-
- ; Handle the event of the drawing area.
- ;
- 'DRAW': begin
-
- WIDGET_CONTROL, sEvent.top, GET_UVALUE=state, /NO_COPY
-
- ; Handle the event for object selection.
- ;
- if (state.modelFlag eq 1) then begin
-
- ; Expose.
- ;
- if (sEvent.type EQ 4) then begin
- state.oWindow->draw, state.oView
- endif
-
- ; Handle trackball update
- ;
- bHaveTransform = state.oTrack->Update(sEvent, TRANSFORM=qmat )
- if (bHaveTransform NE 0) then begin
- state.oShape0Model->GetProperty, TRANSFORM=t
- mt = t # qmat
- state.oShape0Model->SetProperty,TRANSFORM=mt
- state.oShape1Model->SetProperty,TRANSFORM=mt
- endif
-
- ; Button press.
- ;
- if (sEvent.type EQ 0) then begin
- state.btndown = 1B
- state.oWindow->SetProperty, QUALITY=state.dragq
- WIDGET_CONTROL, state.wDraw, /DRAW_MOTION
- endif
-
- ; Button motion.
- ;
- if ((sEvent.type eq 2) and (state.btndown eq 1b)) then begin
- if (bHaveTransform) then begin
- state.oWindow->Draw, state.oView
- endif
- endif
-
- ; Button release.
- ;
- if (sEvent.type eq 1) then begin
- state.btndown = 0b
- state.oWindow->SetProperty, QUALITY=2
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.wDraw, DRAW_MOTION=0
- endif
-
- ; Handle the event for molecule selection
- ;
- endif else begin
-
- ; Expose.
- ;
- if (sEvent.type eq 4) then begin
- state.oWindow->Setproperty, QUALITY=2
- state.initial = 1
- state.oWindow->draw, state.oView
- endif
-
- ; Handle trackball update
- ;
- bHaveTransform = state.oTrack->Update(sEvent, TRANSFORM=qmat )
- if (bHaveTransform NE 0) then begin
- state.oSub1MoleModel->GetProperty, TRANSFORM=t
- mt = t # qmat
- state.oSub1MoleModel->SetProperty,TRANSFORM=mt
- state.oSub2MoleModel->SetProperty,TRANSFORM=mt
- endif
-
- ; Button press.
- ;
- if (sEvent.type EQ 0) then begin
-
- ; Handle the picking of an atom with
- ; the right or center mouse button
- ;
- if ((sEvent.press EQ 4) OR (sEvent.press EQ 2)) then begin
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=0
- picked = state.oWindow->select(state.oView, $
- [sEvent.x,sEvent.y]);
- si = size(picked)
- if (si(0) NE 0) then begin
- picked(0)->GetProperty, UVALUE=uval, TRANSFORM=tm
- case uval of
- 0: atm="C"
- 1: atm="H"
- 2: atm="N"
- 3: atm="S"
- 4: atm="X"
- 5: atm="Ce"
- 6: atm="Br"
- 7: atm="O "
- else: atm="??"
- endcase
- str = string(tm(3,0), tm(3,1), tm(3,2), atm, $
- format='("X=", F6.2, ",Y=", F6.2,'+ $
- '",Z=", F6.2, ",Atom=", A2)')
- new_select, state, OBJ=picked(0)->get()
- endif else begin
- str="No atom picked"
- new_select, state
- endelse
- state.stext.text[9] = str
- textChange = ['atomi', 'void']
- putTips, state.sText, state.wText[1], $
- textChange, [1,2]
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.widgetIDStr.wBase, SENSITIVE=1
-
- ; Handle the interactive change of orientation
- ; with the left mouse button
- ;
- endif else begin
- state.btndown = 1b
- state.oWindow->SetProperty, QUALITY=state.dragq
- state.oMolecule(state.cur_mol+ $
- state.nMolecule)->SetProperty, HIDE=0
- state.oMolecule(state.cur_mol)->SetProperty,HIDE=1
- WIDGET_CONTROL, state.wDraw, /DRAW_MOTION
- endelse
-
- endif ; of sEvent.type EQ 0
-
- ; Button motion.
- ;
- if ((sEvent.type eq 2) and $
- (state.btndown eq 1b)) then begin
-
- if (bHaveTransform) then begin
- state.oWindow->Draw, state.oView
- endif
- endif
-
- ; Button release.
- ;
- if (sEvent.type eq 1) then begin
- state.btndown = 0b
- state.oWindow->SetProperty, QUALITY=2
- state.oMolecule(state.cur_mol+ $
- state.nMolecule)->SetProperty, HIDE=1
- state.oMolecule(state.cur_mol)->SetProperty, HIDE=0
- state.oWindow->Draw, state.oView
- WIDGET_CONTROL, state.wDraw, /DRAW_MOTION
- endif
-
- endelse
-
- WIDGET_CONTROL, sEvent.top, SET_UVALUE=state, /NO_COPY
-
- end ; of DRAW
-
- ; Quit this application.
- ;
- 'QUIT' : BEGIN
- WIDGET_CONTROL, sEvent.top, /DESTROY
- end ; of QUIT
-
- ; Display the information text file.
- ;
- 'ABOUT' : BEGIN
-
- ; Verify that there is only one instance of Xregistered
- ;
- if (Xregistered('XDisplayFile') NE 0) then RETURN
- XDisplayFile, filepath("object3d.txt", $
- SUBDIR=['examples','demo','demotext']), $
- DONE_BUTTON='Done', $
- TITLE="Objects and molecules", $
- GROUP=sEvent.top, WIDTH=55, HEIGHT=14
- end ; of ABOUT
-
- endcase
-
- end ; of event handler
-
- ;-----------------------------------------------------------------
- ;
- ; PURPOSE : cleanup procedure. restore colortable, destroy objects.
- ;
- pro d_object3d_Cleanup, wBase
-
- WIDGET_CONTROL, wBase, GET_UVALUE=state, /NO_COPY
-
- ; Destroy the top objects
- ;
- OBJ_DESTROY, state.oView
- OBJ_DESTROY, state.oContainer
- OBJ_DESTROY, state.oTrack
- OBJ_DESTROY, state.oFont
- OBJ_DESTROY, state.oText
- OBJ_DESTROY, state.spheres0
- OBJ_DESTROY, state.spheres1
- OBJ_DESTROY, state.oSub2MoleModel
- for i = 0, 2*state.nMolecule-1 do begin
- OBJ_DESTROY, state.oMolecule(i)
- endfor
-
- ; Restore the color table.
- ;
- TVLCT, state.colorTable
-
- if WIDGET_INFO(state.groupBase, /VALID_ID) then $
- WIDGET_CONTROL, state.groupBase, /MAP
-
- end ; of Texture_Cleanup
-
- ;----------------------------------------------------------------------------
- ;
- ; PURPOSE : display geometric shaped objects ( moleculres, others..)
- ;
- PRO d_object3d, $
- PATTERN=pattern, $ : IN: (opt) line pattern
- GROUP=group, $ ; IN: (opt) group identifier
- APPTLB = appTLB ; OUT: (opt) TLB of this application
-
-
- ; Check the validity of the group identifier
- ;
- ngroup = N_ELEMENTS(group)
- if (ngroup NE 0) then begin
- check = WIDGET_INFO(group, /VALID_ID)
- if (check NE 1) then begin
- print,'Error, the group identifier is not valid'
- print, 'Return to the main application'
- RETURN
- endif
- groupBase = group
- endif else groupBase = 0L
-
- ; Get the screen dimension and define
- ; the dimension of the drawing area.
- ;
- Device, GET_SCREEN_SIZE=screenSize
- xdim = screenSize(0) * 0.6
- ydim = xdim * 0.8
-
- ; Get the current color vectors to restore
- ; when this application is exited.
- ;
- TVLCT, savedR, savedG, savedB, /GET
-
- ; Build color table from color vectors.
- ;
- colorTable = [[savedR],[savedG],[savedB]]
-
- ; Get the tips.
- ;
- sText = getTips(filepath('object3d.tip', $
- SUBDIR=['examples','demo', 'demotext']) )
-
- ; Get information on molecules.
- ;
- nMolecule = 3 ; number of molecules
- files = STRARR(nMolecule)
-
- files(0) = 'valium.mol'
- files(1) = 'aspartam.mol'
- files(2) = 'caffeine.mol'
-
- ; Create widgets.
- ;
- if (N_ELEMENTS(group) EQ 0) then begin
- wBase = WIDGET_BASE(/COLUMN, $
- XPAD=0, YPAD=0, $
- /TLB_KILL_REQUEST_EVENTS, $
- TLB_FRAME_ATTR=1, MBAR=barBase, TITLE="Three Dimensional Geometry")
- endif else begin
- wBase = WIDGET_BASE(/COLUMN, $
- XPAD=0, YPAD=0, $
- /TLB_KILL_REQUEST_EVENTS, $
- GROUP_LEADER=group, $
- TLB_FRAME_ATTR=1, MBAR=barBase, TITLE="Three Dimensional Geometry")
- endelse
-
- ; Create the menu bar. It contains the file/quit,
- ; edit/ shade-style, help/about.
- ;
- fileMenu = WIDGET_BUTTON(barBase, VALUE='File', /MENU)
-
- wQuitButton = WIDGET_BUTTON(fileMenu, VALUE='Quit', UVALUE='QUIT')
-
-
- ; Create the menu bar item Edit
- ; that has the shade and style options
- ;
- wEditButton = WIDGET_BUTTON(barBase, VALUE='Options', /MENU)
-
- wShadingButton = WIDGET_BUTTON( wEditButton, $
- VALUE='Shading', UVALUE='SHADING', MENU=1)
-
- wFlatButton = WIDGET_BUTTON(wShadingButton, $
- VALUE='Flat', UVALUE='FLAT')
-
- wGouraudButton = WIDGET_BUTTON(wShadingButton, $
- VALUE='Gouraud', UVALUE='GOURAUD')
-
- wStyleButton = WIDGET_BUTTON(wEditButton, $
- VALUE='Style', UVALUE='STYLE', /MENU)
-
- wPointsButton = WIDGET_BUTTON(wStyleButton, $
- VALUE='Points', UVALUE='POINTS')
-
- wWireButton = WIDGET_BUTTON(wStyleButton, $
- VALUE='Wire', UVALUE='WIRE')
-
- wSolidButton = WIDGET_BUTTON(wStyleButton, $
- VALUE='Solid', UVALUE='SOLID')
-
- wPointhButton = WIDGET_BUTTON(wStyleButton, $
- VALUE='Hidden Points', UVALUE='POINTSH')
-
- wWirehButton = WIDGET_BUTTON(wStyleButton, $
- VALUE='Hidden Wire', UVALUE='WIREH')
-
- tBack = WIDGET_BUTTON(wEditButton, $
- VALUE="Backface Culling (off)", UVALUE='BACKF')
-
- tVc = Widget_Button(wEditButton, $
- VALUE="Vertex Coloring (on )", UVALUE='VERTC')
-
- tEdging = WIDGET_BUTTON(wEditButton, $
- VALUE="Edging (off)", UVALUE='EDGING')
-
- wBottomButton = WIDGET_BUTTON(wEditButton, $
- VALUE="Bottom Color (on )", UVALUE='BOTTOM')
-
- wThickButton = WIDGET_BUTTON(wEditButton, $
- MENU=2, VALUE="Line Thickness")
-
- wThk1 = WIDGET_BUTTON(wThickButton, $
- VALUE='1', UVALUE='THCK1')
-
- wThk3 = WIDGET_BUTTON(wThickButton, $
- VALUE='3', UVALUE='THCK3')
-
- wThk5 = WIDGET_BUTTON(wThickButton, $
- VALUE='5', UVALUE='THCK5')
-
- wThk7 = WIDGET_BUTTON(wThickButton, $
- VALUE='7', UVALUE='THCK7')
-
-
- ; Create the drag buttons
- ;
- wOptionButton = WIDGET_BUTTON(barBase, VALUE='Drag', /MENU)
-
- tDrag = WIDGET_BUTTON(wOptionButton, $
- VALUE="Drag Quality", UVALUE='DRAGQ', /MENU)
-
- wLowButton = WIDGET_BUTTON(tdrag, $
- VALUE='Low', UVALUE='LOW')
-
- wMediumButton = WIDGET_BUTTON(tdrag, $
- VALUE='Medium', UVALUE='MEDIUM')
-
- wHighButton = WIDGET_BUTTON(tdrag, $
- VALUE='High', UVALUE='HIGH')
-
- ; Create the help|About button.
- ;
- helpMenu = WIDGET_BUTTON(barBase, VALUE='About', /HELP, /MENU)
-
- wAboutButton = WIDGET_BUTTON(helpMenu, $
- VALUE='About 3-D Geometry', UVALUE='ABOUT')
-
- ; Create a sub base of the top base (wBase)
- ;
- subBase = WIDGET_BASE(wBase, COLUMN=2)
-
-
- ; Create the left Base that contains the functionality buttons
- ; Notably the object list and the option list
- ;
- wLeftbase = WIDGET_BASE(subBase, $
- /BASE_ALIGN_CENTER, /COLUMN)
-
- wObjectBase = WIDGET_BASE(wLeftBase, /COLUMN, $
- /BASE_ALIGN_CENTER)
-
- wObjectLabel = WIDGET_LABEL(wObjectBase, $
- VALUE='Objects' )
-
- wObjectBgroup = cw_bgroup(wObjectBase, $
- [ 'Seashell','Knot','Teapot', $
- 'Valium Molecule', 'Aspartame Molecule', $
- 'Caffeine Molecule'], $
- /COLUMN, $
- /EXCLUSIVE, $
- /NO_RELEASE, $
- /RETURN_INDEX, $
- SET_VALUE=0, $
- UVALUE='OBJ')
-
- wScalingBase = WIDGET_BASE(wLeftBase, $
- /COLUMN, YPAD=5)
-
- percent = 100
- scalingString = 'Scaling : ' + STRING(percent, $
- FORMAT='(f5.1)') + ' %'
- wScalingLabel = WIDGET_LABEL(wScalingBase, $
- VALUE=scalingString)
-
- wScalingSlider = WIDGET_SLIDER(wScalingBase, $
- MINIMUM=0, $
- MAXIMUM=50, VALUE=25, $
- /SUPPRESS_VALUE, $
- UVALUE='SCALING')
-
- wResetBase = WIDGET_BASE(wLeftBase, /COLUMN, YPAD=5)
-
- wResetLabel = WIDGET_LABEL(wResetBase, $
- VALUE='Reset Orientation')
-
- wResetButton = WIDGET_BUTTON(wResetBase, $
- VALUE="Reset", UVALUE='RESETTRANSFORM')
-
- ; Create the right Base that has the drawing area
- ;
- wRightbase = WIDGET_BASE(subBase, /COLUMN)
-
- wDraw = widget_draw(wRightBase, $
- GRAPHICS_LEVEL=2, $
- XSIZE=xdim, YSIZE=ydim, /BUTTON_EVENTS, $
- UVALUE='DRAW', $
- RETAIN=0, /EXPOSE_EVENTS)
-
- ; Create tips texts.
- ;
- wStatusBase = WIDGET_BASE(wBase, MAP=0, /ROW)
-
- nWidgets = 2
- wText = LONARR(nWidgets)
- widTips, wStatusBase, sText.text, XSIZE=36, $
- YSIZE=3, NWIDGETS=nWidgets, wText
-
- ; Realize the base widget.
- ;
- WIDGET_CONTROL, wBase, /REALIZE
-
- WIDGET_CONTROL, /HOURGLASS
-
- ; Returns the top level base in the appTLB keyword.
- ;
- appTLB = wBase
-
- ; Size the tips widgets.
- ;
- sizeTips, wBase, wText, wStatusBase
-
- WIDGET_CONTROL, wBase, SENSITIVE=0
-
- ; Grab the window id of the drawable.
- ;
- WIDGET_CONTROL, wDraw, GET_VALUE=oWindow
-
- ; Compute viewplane rect based on aspect ratio.
- ;
- aspect = float(xdim)/float(ydim)
- myview = [-0.5,-0.5,1,1]
- if (aspect > 1) then begin
- myview(0) = myview(0) - ((aspect-1.0)*myview(2))/2.0
- myview(2) = myview(2) * aspect
- endif else begin
- myview(1) = myview(1) - (((1.0/aspect)-1.0)*myview(3))/2.0
- myview(3) = myview(3) * aspect
- endelse
-
- ; Create view.
- ;
- oView = OBJ_NEW('idlgrview', PROJECTION=2, EYE=3, ZCLIP=[1.5,-1.5],$
- VIEWPLANE_RECT=myview, COLOR=[0,0,0])
-
- ; Create a centered starting up text.
- ;
- textLocation = [myview[0]+0.5*myview[2], myview[1]+0.5*myview[3]]
-
- ; Create and display the PLEASE WAIT text.
- ;
- oFont = OBJ_NEW('IDLgrFont', 'Helvetica', SIZE=18)
- oText = OBJ_NEW('IDLgrText', $
- 'Starting up Please wait...', $
- ALIGN=0.5, $
- LOCATION=textLocation, $
- COLOR=[255,255,0], FONT=oFont)
-
- ; Create models and objects for the modlecules .
- ;
- nMolecule = 3 ; number of molecules
- oMoleModel = OBJ_NEW('idlgrModel')
- oSub1MoleModel = OBJ_NEW('idlgrModel')
- oSub2MoleModel = OBJ_NEW('idlgrModel')
- oView->Add, oMoleModel
- oMoleModel->Add, oSub1MoleModel
- oMoleModel->Add, oText
- oWindow->Draw, oView
-
- scm = 0.3
- oMoleModel->Scale, scm, scm, scm
- oMolecule = OBJARR(nMolecule*2)
- spheres0 = makeSpheres()
- spheres1 = makeSpheres()
-
- for i = 0, N_ELEMENTS(spheres1)-1 do begin
- spheres1(i)->SetProperty, DENSITY=0.3
- endfor
-
- for i = 0, N_ELEMENTS(spheres0)-1 do begin
- spheres0(i)->SetProperty, DENSITY=0.9
- endfor
-
- high = FLTARR(3)
- low = FLTARR(3)
-
- for i=0,nMolecule-1 do begin
- n = molread(files(i), xyz, type)
-
- for j=0,2 do begin
- high(j) = max(xyz(j,*))
- low(j) = min(xyz(j,*))
- endfor
-
- sc = 2.0/float(high(0)-low(0))
- oMolecule(i) = makemolecule(n, xyz, type, spheres0)
- oMolecule(i)->Scale, sc, sc, sc
- oSub1MoleModel->Add, oMolecule(i)
-
- oMolecule(i)->SetProperty, HIDE=1
-
- oMolecule(i+nMolecule) = makemolecule(n,xyz,type,spheres1)
- oMolecule(i+nMolecule)->Scale, sc, sc, sc
- oMolecule(i+nMolecule)->SetProperty, HIDE=1
- oSub1MoleModel->add,oMolecule(i+nMolecule)
- endfor
-
- ; Create some lights.
- ;
- oLight1 = OBJ_NEW('IDLgrLight', $
- LOCATION=[2,2,5], TYPE=2, COLOR=[255,255,255], $
- INTENSITY=0.25 )
-
- oMoleModel->Add, oLight1
-
- oLight2 = OBJ_NEW('IDLgrLight', TYPE=0, $
- INTENSITY=0.5, COLOR=[255,255,255])
-
- oMoleModel->add,oLight2
-
- ; Hide the molecule model.
- ;
- oMoleModel->SetProperty, HIDE=1
-
- ; Create model for the geometric objects.
- ;
- oShapeModel = OBJ_NEW('IDLgrModel')
- oShape0Model = OBJ_NEW('IDLgrModel')
- oShapeModel->Add, oShape0Model
- goff = OBJ_NEW('IDLgrModel')
- oShapeModel->Add, goff
- goff->translate, 0, 0, 0.005
- oShape1Model = OBJ_NEW('IDLgrModel')
- goff->Add, oShape1Model
-
- max_obj = 3 ; number of objects
- oSurface = OBJARR(max_obj)
-
- scs = 0.7
- oShapeModel->Scale, scs, scs, scs
-
- ; Read_noff can be used to read modified .noff format files
- ; which are ascii data files containing a mesh description
- ; The d_object3d demo uses object3d_read_data to read binary
- ; files which contain the meshes which were originally in ascii files.
- ;oSurface(0) = read_noff('seashell.nof', oShape0Model, xr, yr, zr)
- ;oSurface(1) = read_noff('knot.nof', oShape0Model, xr, yr, zr)
- ;oSurface(2) = read_noff('teapot.nof', oShape0Model, xr, yr, zr)
- oSurface(0) = object3d_read_data('seashell.dat', oShape0Model, xr, yr, zr)
- oSurface(1) = object3d_read_data('knot.dat', oShape0Model, xr, yr, zr)
- oSurface(2) = object3d_read_data('teapot.dat', oShape0Model, xr, yr, zr)
-
- ; Create the vertex colors and make the 3-D objects
- ; to hqve these color.
- ;
- vc = BYTARR(3, 360, /NOZERO)
- sat = 1.0
- val = 1.0
- for i = 0, 359 do begin
- angle = i
- Color_convert, angle, sat, val, red, green, blue, /HSV_RGB
- vc(0, i) = red
- vc(1, i) = green
- vc(2, i) = blue
- endfor
-
- for i = 0, 2 do begin
- oSurface(i)->SetProperty, VERT_COLORS=vc
- endfor
-
- for i = 1, max_obj-1 do begin
- oSurface(i)->SetProperty, HIDE=1
- endfor
-
- for i=0,max_obj-1 do begin
- oSurface(i)->GetProperty, XRANGE=xr, YRANGE=yr, ZRANGE=zr
- endfor
-
- ; Cook up polyline objects using share_data.
- ;
- sh = OBJARR(max_obj)
- for i=0,max_obj-1 do begin
- oSurface(i)->GetProperty, POLY=pmesh
- sh(i) = OBJ_NEW('IDLgrPolyline', COLOR=[0,0,0], $
- SHARE_DATA=oSurface(i), POLYLINE=pmesh, HIDE=1)
- oShape1Model->Add, sh(i)
- endfor
-
- ; Create some lights.
- ;
- oLight3 = OBJ_NEW('IDLgrLight', LOCATION=[2,2,5], TYPE=1, $
- COLOR=[200,0,0])
- oShapeModel->Add, oLight3
-
- oLight4 = OBJ_NEW('IDLgrLight', LOCATION=[0,0,5], TYPE=1, $
- COLOR=[180,180,180], INTENSITY=0.5)
- oShapeModel->Add, oLight4
-
- oLight5 = OBJ_NEW('IDLgrLight', TYPE=0, INTENSITY=0.3, $
- COLOR=[100,100,255])
- oShapeModel->Add, oLight5
-
- ; Set the line pattern.
- ;
- if (N_Elements(Pattern) NE 0) then begin
- pat = BYTARR(4,2,16)
- pat(*,0,*) = 'AA'X
- pat(*,1,*) = '55'X
-
- if (Pattern NE 1) then begin
- pobj= OBJ_NEW('IDLgrPattern','PATTERN',pattern=pat)
- endif else begin
- pobj= OBJ_NEW('IDLgrPattern','LINEFILL',$
- spacing=10,orientation=30,thick=4)
- endelse
-
- for i=0, max_obj do begin
- oSurface(i)->SetProperty,fill_pattern=pobj
- endfor
-
- tPAnim = WIDGET_BUTTON(wOptions, $
- VALUE="Pat Animate", UVALUE='PANIMATE')
- endif
-
- ; Place the model in the view.
- ;
- oView->Add, oShapeModel
-
- ; Desensitize the appropriate buttons.
- ;
- WIDGET_CONTROL, wGouraudButton, SENSITIVE=0
- WIDGET_CONTROL, wSolidButton, SENSITIVE=0
- WIDGET_CONTROL, wMediumButton, SENSITIVE=0
- WIDGET_CONTROL, wThk1, SENSITIVE=0
- WIDGET_CONTROL, wThickButton, SENSITIVE=0
-
- oShape0Model->GetProperty, TRANSFORM=tmg0
- oShape1Model->GetProperty, TRANSFORM=tmg1
- oSub1MoleModel->GetProperty, TRANSFORM=tmMolecule
-
- ; Create a structure that has the widget ID
- ;
- widgetIDStr = { $
- WBase : wBase, $ ; Top level base
- WEditButton : wEditButton, $
- WQuitButton : wQuitButton, $
- WAboutButton : wAboutButton, $
- WFlatButton : wFlatButton, $
- WGouraudButton : wGouraudButton, $
- WPointsButton : wPointsButton, $
- WWireButton : wWireButton, $
- WSolidButton : wSolidButton, $
- WPointhButton : wPointhButton, $
- WWirehButton : wWirehButton, $
- WLowButton : wLowButton, $
- WMediumButton : wMediumButton, $
- WHighButton : wHighButton, $
- WBottomButton : wBottomButton, $
- WThickButton : wThickButton, $
- wObjectBgroup : wObjectBgroup, $
- WScalingSlider : wScalingSlider, $
- WScalingLabel : wScalingLabel, $
- WThk1 : wThk1, $ ; Line thickness buttons
- WThk3 : wThk3, $
- WThk5 : wThk5, $
- WThk7 : wThk7 $
- }
-
- ; Add the trackball object for interactive change
- ; of the scene orientation.
- ;
- oTrack = OBJ_NEW('Trackball', [xdim/2.0, ydim/2.0], xdim/2.0)
-
- oContainer = OBJ_NEW('IDLgrContainer')
- oContainer->Add, oView
- oContainer->Add, oTrack
-
-
- ; Save state.
- ;
- state = { $
- tmg0: tmg0, $ ; Transformation matrix for model g0
- tmg1: tmg1, $ ; Transformation matrix for model g1
- tmmolecule: tmmolecule, $ ; Transformation matrix for molecule
- ModelFlag:1, $ ; 0 = molecule , 1 = object
- btndown: 0b, $ ; 0 = bottom not pressed, pressed otherwise
- wDraw: wDraw, $ ; Widget draw ID
- OShapeModel: oShapeModel, $ ; 3-D objects model
- OMoleModel: oMoleModel, $ ; Molecule model
- Spheres0: spheres0, $ ; Spheres objects for molecules
- Spheres1: spheres1, $
- OShape0Model: oShape0Model, $ ; Models for 3-D objects
- OShape1Model: oShape1Model, $
- OSurface: oSurface, $ ; Surface object
- OMolecule: oMolecule, $ ; Molecule object
- sh : sh, $ ; Share data (3-D objects)
- OView: oView, $ ; View object
- OWindow: oWindow, $ ; Window object
- max_obj: max_obj, $ ; Number of 3-D objects
- NMolecule: nMolecule, $ ; Number of molecule
- cur_obj: 0, $ ; Current 3-D object
- cur_mol: 0, $ ; Current molecule
- cur_sel: oSub2MoleModel, $ ; Molecule models
- OSub1MoleModel: oSub1MoleModel, $
- OSub2MoleModel: oSub2MoleModel, $
- OContainer: oContainer, $ ; Container object
- OTrack: oTrack, $ ; Trackball object
- is_sel: 0, $ ; Is selected flag (for picking molecule)
- edging: 0, $ ; Edges flag (0=not showing, 1=showing)
- WidgetIDStr : widgetIDStr, $ ; Structure of all the widget IDS
- Initial:0, $ ; Indicates if initial draw
- ColorTable: colorTable, $ ; Color table to restore
- SText: sText, $ ; Text structure for tips
- OText: oText, $ ; Text object
- OFont: oFont, $ ; Font object
- WText: wText, $ ; Widget text IDs for tips
- Vc: vc, $ ; Vertex colors array
- dragq: 1, $ ; Drag quality (0=low, 1=med., 2=high)
- groupBase: groupBase $ ; Base of Group Leader
- }
-
- WIDGET_CONTROL, wBase, SET_UVALUE=state, /NO_COPY
-
-
- WIDGET_CONTROL, wBase, SENSITIVE=1
-
- oMoleModel->Remove, oText
-
- oWindow->Draw, oView
-
- XMANAGER, 'd_object3d', wBase, Event_Handler='d_object3d_Event', $
- /NO_BLOCK, $
- CLEANUP='d_object3d_cleanup'
-
- end ; of d_object3d
-